<?php
$section = "user_admin";

$titre = _LB_ACCOUNT_MANAGEMENT;
$smarty->assign('titre', $titre);

$user_id = Request::getIntNumber("user_id");
$act = Request::getIntNumber("act");

$login = new Login();
$login->get($user_id);

$backlink = Session::getBackLink("user",APPLICATION_URL."/user_admin/list/?");

// check permission if current user type is annonceur

if ($_SESSION["is_annonceur"] && $_SESSION["annonceurID"]!=$login->ID_ANNONCEUR )
	redirect($backlink);

if ($act==ACT_VALID_EDIT)
{
    $pass_confirm = Request::get('PASS_CONFIRM');
    $password = Request::get('PASSWORD');

    if (trim($password) == "" || trim($pass_confirm) == "")
    {
        $error_msg->add(_LB_INVALID_PASSWORD);
    }
    elseif(!Utils::isValidLength($password, MAX_LENGTH_PASSWORD))
    {
        $error_msg->add(_MSG_PASSWORD_IS_TOO_LONG);
    }
    elseif(!Utils::isValidMinLength($password, MIN_LENGTH_PASSWORD))
    {
        $error_msg->add(_MSG_PASSWORD_IS_TOO_SHORT);
    }
    elseif ($password != $pass_confirm)
    {
        $error_msg->add(_LB_PASSWORD_DOESNT_MATCH);
    }

    if (!sizeof($error_msg->errors))
    {
        $login->PASS = sha1($password);
        $login->update();
        redirect($backlink);
    }
}


$cfer = new Cfer(array(
        _LB_ACCUEIL => Utils::getHomeLink(),
        _LB_USER_MANAGEMENT => APPLICATION_URL."/user_admin/list/?",
        _LB_CHANGE_PASSWORD => Utils::getCurrentLink()
    ));

$smarty->assign("cfer",$cfer);
$smarty->assign("login",$login);
$smarty->assign("backlink",$backlink);
$smarty->display("user_change_password.html");